package com.github.shiqiyue.learn.elasticsearch;

import org.apache.http.HttpHost;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;

/***
 *
 * @author wenyao.wu
 * @date 2019/1/21
 */
public class EsUtil {

    public static final HttpHost[] DEFAULT_HTTP_HOSTS = {new HttpHost("localhost", 9200, "http")};

    /***
     * 获取客户端
     * @param httpHosts
     * @return
     */
    public static RestHighLevelClient getClient(HttpHost... httpHosts) {
        if (httpHosts == null) {
            httpHosts = DEFAULT_HTTP_HOSTS;
        }
        RestHighLevelClient client = new RestHighLevelClient(
                RestClient.builder(httpHosts));
        return client;
    }
}
